package com.tcs.util.bean;

import java.lang.reflect.Field;
import java.util.Map;

import com.google.common.collect.Maps;

/**
* @Title: BeanUtils.java
* @Package com.tcs.util.bean
* @author 神经刀
* @date 2018年8月9日
* @version V1.0
 */
public final class BeanUtils {

	private BeanUtils() {};
	
	/**
	* @Title: BeanToMap  
	* @Description: Object转Map
	* @param bean {@link Object}
	* @throws NullPointerException : {@link NullPointerException}
	* @throws IllegalArgumentException : {@link IllegalArgumentException}
	* @throws IllegalAccessException : {@link IllegalAccessException}
	* @return Map<String,Object>  
	 */
	public final static Map<String,Object> BeanToMap(Object bean) throws NullPointerException, IllegalArgumentException, IllegalAccessException {
		Map<String,Object> returnMap = Maps.newHashMap();
		if (null == bean) throw new NullPointerException("bean为null.");
		Field [] fieldArray = bean.getClass().getDeclaredFields();
		for (Field field : fieldArray) {
			field.setAccessible(true);
			Object obj = field.get(bean);
			if (null != obj) returnMap.put(field.getName(), obj);
		}
		return returnMap;
	}
}